package CustSys;

import java.security.PublicKey;

public class CustomerList {
    Customer[] customers;//用来保存客户对象的数组
    int total = 0;           // 记录已保存客户对象的数量



    public CustomerList(int totalCustomer){
        customers = new Customer[totalCustomer];
    }

    public boolean addCustomer(Customer customer){
        if(total>=customers.length){
            return false;
        }
        return true;
    }
    public boolean replaceCustomer(int index, Customer cust){
        if(index<0||index>=total){
            return false;
        }
        customers[total] = cust;
        total++;
        return true;
    }
    public boolean deleteCustomer(int index){
        if(index<0||index>=total){
            return false;
        }
        for (int i = 0; i <total-1 ; i++) {
            customers[i] = customers[i+1];
        }
        customers[total-1] = null;
        total--;
        return true;
    }
    public Customer[] getAllCustomers(){
        Customer[] custs = new Customer[total];
        for (int i = 0; i <total ; i++) {
            custs[i] = customers[i];
        }
        return custs;
    }
    public Customer getCustomer(int index){
        if(index<0||index>=total) {
            return null;
        }
        return customers[index];
    }
    public int getTotal(){
        return total;
    }

}
